package com.mew.chess.core.game.pokdeng.game.task;

import com.mew.chess.core.common.handler.ChessPushMessageUtil;
import com.mew.chess.core.game.pokdeng.game.PokDengGameManager;
import com.mew.chess.core.game.pokdeng.game.PokDengTableManager;
import com.mew.chess.core.game.pokdeng.game.common.PokDengConstantValue;
import com.mew.chess.core.game.pokdeng.game.common.PokDengLinkType;
import com.mew.chess.core.game.pokdeng.game.common.PokDengPushCMDMapType;
import com.mew.chess.core.game.pokdeng.game.message.PushAskCardMessage;
import com.mew.common.dc.redis.GameRoomRedisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author dylin
 * @create 2021/4/29
 */
@Component
@Slf4j
public class PokDengAskCardTask {
    @Autowired
    private GameRoomRedisService gameRoomRedisService;

    public void askCard(int roomId,int tableId,int seatNo){
        PokDengTableManager table = PokDengGameManager.getInstance().getController(roomId).getTableManager(tableId);
        table.setAskNowSeat(seatNo);
        PushAskCardMessage askCardMessage =table.getPushAskCardMessage();
        askCardMessage.setSeatNo(seatNo);
        ChessPushMessageUtil.broadcastMessage(table.getOnlineUser().values(), PokDengPushCMDMapType.AskCardMessage.code(),askCardMessage);
        table.changeLink(PokDengLinkType.AskCard.code(), PokDengConstantValue.ASK_CARD_TIME);
    }

    public boolean hasControl(int roomId){
        return gameRoomRedisService.isCapacityControl(PokDengGameManager.getInstance().getGameId(),  roomId);
    }

}
